//
//  ActivitiesView.m
//  TravelFirst
//
//  Created by lanou3g on 15/9/18.
//  Copyright (c) 2015年 吴娅君. All rights reserved.
//

#import "ActivitiesView.h"

@implementation ActivitiesView

- (instancetype)initWithFrame:(CGRect)frame imageArray:(NSMutableArray *)imageArray delegate:(id)delegate action:(SEL)action timer:(NSTimeInterval)timer selector:(SEL)selector{
    self = [super initWithFrame:frame];
    if(self){
        NSMutableArray *insterArray = [NSMutableArray arrayWithArray:imageArray];
        //把imageArray的最后一个插入到第0个
        [insterArray insertObject:[imageArray objectAtIndex:imageArray.count - 1] atIndex:0];
        [insterArray insertObject:[imageArray objectAtIndex:0] atIndex:imageArray.count + 1];
        //设置ScrollerView的相关属性
        self.contentSize = CGSizeMake(kWidth * insterArray.count, 0);
        self.pagingEnabled = YES;
        self.showsHorizontalScrollIndicator = YES;
        self.bounces = NO;
        self.delegate = delegate;
        self.contentOffset = CGPointMake(kWidth, 0);
        //循环创建imageView
        for(int i = 0; i < insterArray.count ;i++){
            TapImageView *imageTap = [[TapImageView alloc] initWithFrame:CGRectMake(i  * kWidth, 0, kWidth, self.bounds.size.height) taget:delegate action:action];
            [imageTap sd_setImageWithURL:[NSURL URLWithString:[insterArray objectAtIndex:i]]];
            [self addSubview:imageTap];
        }
        //创建定时器
        [NSTimer scheduledTimerWithTimeInterval:timer target:delegate selector:selector userInfo:nil repeats:YES];
    }
    return self;
}

@end
